package com.seo.utils;

import java.nio.charset.Charset;
import java.security.MessageDigest;

import com.seo.utils.codec.Hex;

/**
 * MD5Util
 * @author Administrator 说明：日期处理 创建人：FH Q313596790
 * @version 2017.12.01 11:40
 */
public class MD5Util {
    private MD5Util() {
    }

    /**
     * MD5
     * @param s s
     * @return String
     * @author Administrator 说明：日期处理 创建人：FH Q313596790
     * @version 2017.12.01 11:40
     */
    public static String MD5(String s) {
        return MD5Encode(s, Charset.defaultCharset().name());
    }

    /**
     * MD5Encode
     * @param origin origin
     * @param charsetname charsetname
     * @return String
     * @author Administrator 说明：日期处理 创建人：FH Q313596790
     * @version 2017.12.01 11:40
     */
    public static String MD5Encode(String origin, String charsetname) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] b = md.digest(origin.getBytes());
            return new String(Hex.encodeHex(b, true));
        } catch (Exception e) {
            throw new RuntimeException("MD5摘要生成失败", e);
        }
    }
    
    public static String encode(String code){
    	try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] b = md.digest(code.getBytes());
            return new String(Hex.encodeHex(b, false));
        } catch (Exception e) {
            throw new RuntimeException("MD5摘要生成失败", e);
        }
    }
}
